import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
import flash.display.Shape;
import flash.text.TextFormat;

import neash.text.KeyCode;
import neash.Lib;

/*
   This code still leaves a lot to do.

   NME, and therefore neash, has a "magic" font path built in.
   It will look in the "./fonts" subdirectory and the "./data" subdirectory for
   the font - note this is case-sensitive on unix/linux.

   On windows, fonts may be found in the standard font area.

   This example compares text generated using the freetype renderer with text
    generated with the standard renderer.

*/

class Text
{
   
   public static function main()
   {
#if js
						haxe.Firebug.redirectTraces();
#end
      neash.Lib.Init("Text Demo",640,480);
      neash.Lib.SetBackgroundColour(0xa0a0ff);
      //neash.text.NeashText.mDefaultFont = "Tuffy";

      var cursor = new Shape();
      var gfx = cursor.graphics;
      gfx.lineStyle(1,0x000000);
      gfx.moveTo(-5,0);
      gfx.lineTo( 6,0);
      gfx.moveTo(0,-5);
      gfx.lineTo(0, 6);
      neash.Lib.current.stage.addChild(cursor);

      neash.Lib.ShowCursor(false);
      flash.Lib.current.stage.addEventListener(MouseEvent.MOUSE_MOVE,
        function(e:MouseEvent)
        {
        var sx = cursor.scaleX = 1.0/flash.Lib.current.stage.scaleX;
        var sy = cursor.scaleY = 1.0/flash.Lib.current.stage.scaleY;
        cursor.x = e.stageX*sx;
        cursor.y = e.stageY*sy;
        });


      var text1 = new TextField();
      #if (neko||cpp)
      text1.mTryFreeType = true;
      #end
      text1.htmlText = "Hello to <font size='20'>YOU</font> abcdefghijklmopqrstuvwxyz! (ft)";
      text1.x = 80;
      text1.y = 80;
      text1.border = true;
      text1.borderColor = 0xff0000;
      text1.textColor = 0x0000ff;
      text1.autoSize = TextFieldAutoSize.LEFT;
      flash.Lib.current.addChild(text1);

      var text2 = new TextField();
      #if (neko||cpp)
      text2.mTryFreeType = false;
      #end
      text2.autoSize = TextFieldAutoSize.LEFT;
      text2.htmlText = "Hello to <font size='20'>YOU</font> abcdefghijklmopqrstuvwxyz! (not-ft)";
      text2.x = 80;
      text2.y = 120;
      text2.borderColor = 0x00ff00;
      text2.border = true;
      // text2.type = flash.text.TextFieldType.INPUT;
      flash.Lib.current.addChild(text2);

      // flash.Lib.current.removeChild(text2);


      var text3 = new TextField();
      text3.text = "Hello World";
      text3.x = 80;
      text3.y = 160;
      var fmt = new TextFormat();
      fmt.size = 24;
      text3.setTextFormat(fmt);
      flash.Lib.current.addChild(text3);
      text3.type = flash.text.TextFieldType.INPUT;
      text3.border = true;
      text3.autoSize = flash.text.TextFieldAutoSize.LEFT;
      flash.Lib.current.addChild(text3);
      
      text3.stage.focus = text3;


      var text4 = new TextField();
      text4.text = "Fixed Width";
      text4.x = 80;
      text4.y = 200;
      text4.width = 300;
      text4.height = 30;
      var fmt = new TextFormat();
      fmt.size = 24;
      fmt.align = flash.text.TextFormatAlign.CENTER;
      text4.setTextFormat(fmt);
      text4.type = flash.text.TextFieldType.INPUT;
      text4.border = true;
      text4.autoSize = flash.text.TextFieldAutoSize.NONE;
      text4.background = true;
      text4.backgroundColor = 0xffa0a0;
      flash.Lib.current.addChild(text4);



      var text5 = new TextField();
      text5.x = 80;
      text5.y = 240;
      text5.width = 300;
      text5.height = 80;
      text5.multiline = true;
      var fmt = new TextFormat();
      fmt.size = 24;
      text5.setTextFormat(fmt);
      flash.Lib.current.addChild(text5);
      text5.border = true;
      text5.autoSize = flash.text.TextFieldAutoSize.NONE;
      text5.background = true;
      text5.wordWrap = true;
      text5.backgroundColor = 0xe0e0e0;
      text5.htmlText = "<font size='24'><p align='center'>Multi-line - <font color='#ff0000'>here</font> are some words of wisdom...</p><p align='right'>Let it be</p></font>";
      flash.Lib.current.addChild(text5);



      neash.Lib.Run();
   }
}

